﻿namespace ExamV5.GradeInfo
{
    using ExamV5;
    using System;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;

    public class FrmCountGradeAN : Page
    {
        protected HtmlForm form1;
        protected HtmlHead Head1;
        private int int_0 = 0;
        private int int_1 = 1;
        protected Label labtableInfo;
        protected Label labTitle;
        private PublicFun publicFun_0 = new PublicFun();
        protected ScriptManager SM;
        private string string_0 = "";
        private string string_1 = "0";
        private string string_2 = "";
        private string string_3 = "";
        protected UpdatePanel UPPart;

        private void method_0(string string_4, string string_5, string string_6)
        {
            string str = "";
            str = "<tr>";
            str = ((((((((((((((((((((((((((((((str + "<td>") + "<table cellSpacing='0' cellPadding='0' width='100%' align='center' border='0'>" + "<tr>") + "<td width='50%'>单位：(" + string_5 + ")</td>") + "<td width='50%' align='right'>考试时间：" + this.string_0 + "</td>") + "</tr>" + "<tr>") + "<td colspan='2'>" + "<table cellSpacing='0' cellPadding='0' width='100%' align='center' border='1' bordercolordark='#cccccc' bordercolorlight='#cccccc'  bordercolor='#cccccc' class='tableStyle'>") + "<tr>" + "<td rowspan='3' align='center' width=30>序号</td>") + "<td rowspan='3' align='center'>单位/部门名称</td>" + "<td rowspan='2' align='center' width=70>应考人数</td>") + "<td rowspan='2' align='center' width=70>实考人数</td>" + "<td rowspan='2' align='center' width=60>实考比例</td>") + "<td colspan='2' align='center' width=120>" + this.publicFun_0.GetValues("select ReuleName+'('+Convert(varchar,MinValue)+'-'+Convert(varchar,MaxValue)+')' as ReuleNameTmp from GradeReule where PaperID=" + this.int_0 + " and StandFlag='D'", "ReuleNameTmp") + "</td>") + "<td colspan='2' align='center' width=120>" + this.publicFun_0.GetValues("select ReuleName+'('+Convert(varchar,MinValue)+'-'+Convert(varchar,MaxValue)+')' as ReuleNameTmp from GradeReule where PaperID=" + this.int_0 + " and StandFlag='C'", "ReuleNameTmp") + "</td>") + "<td colspan='2' align='center' width=120>" + this.publicFun_0.GetValues("select ReuleName+'('+Convert(varchar,MinValue)+'-'+Convert(varchar,MaxValue)+')' as ReuleNameTmp from GradeReule where PaperID=" + this.int_0 + " and StandFlag='B'", "ReuleNameTmp") + "</td>") + "<td colspan='2' align='center' width=120>" + this.publicFun_0.GetValues("select ReuleName+'('+Convert(varchar,MinValue)+'-'+Convert(varchar,MaxValue)+')' as ReuleNameTmp from GradeReule where PaperID=" + this.int_0 + " and StandFlag='A'", "ReuleNameTmp") + "</td>") + "<td rowspan='2' align='center' width=45>平均分</td>") + "<td rowspan='2' align='center' width=35>排名</td>" + "</tr>") + "<tr>" + "<td align='center' width=50>人数</td>") + "<td align='center' width=60>未及格率</td>" + "<td align='center' width=50>人数</td>") + "<td align='center' width=60>应考比例</td>" + "<td align='center' width=50>人数</td>") + "<td align='center' width=60>应考比例</td>" + "<td align='center' width=50>人数</td>") + "<td align='center' width=60>应考比例</td>" + "</tr>") + "<tr>" + "<td align='center'>人</td>") + "<td align='center'>人</td>" + "<td align='center'>％</td>") + "<td align='center'>人</td>" + "<td align='center'>％</td>") + "<td align='center'>人</td>" + "<td align='center'>％</td>") + "<td align='center'>人</td>" + "<td align='center'>％</td>") + "<td align='center'>人</td>" + "<td align='center'>％</td>") + "<td align='center'>分</td>" + "<td align='center'>&nbsp;</td>") + "</tr>" + this.method_1(string_4, string_6)) + "</table>" + "</td>") + "</tr>" + "</table>") + "</td>" + "</tr>";
            this.labtableInfo.Text = this.labtableInfo.Text + str + "<tr height=30><td></td><tr>";
        }

        private string method_1(string string_4, string string_5)
        {
            string values = "";
            int num = 0;
            double num2 = 0.0;
            double num3 = 0.0;
            string connectionString = ConfigurationManager.ConnectionStrings["Conn"].ConnectionString;
            values = this.publicFun_0.GetValues("select Count(*) as DeptCount from DeptInfo where UPID=" + string_4, "DeptCount");
            if (values.Trim() != "")
            {
                this.int_1 = Convert.ToInt32(values.Trim());
            }
            string[,] strArray = new string[this.int_1, 0x10];
            string str25 = "0";
            string str26 = "0";
            string str23 = "0";
            string str24 = "0";
            string str21 = "0";
            string str22 = "0";
            string str19 = "0";
            string str20 = "0";
            SqlConnection connection2 = new SqlConnection(connectionString);
            connection2.Open();
            SqlCommand command = new SqlCommand("select MinValue,MaxValue,StandFlag from GradeReule where PaperID=" + this.int_0 + " order by StandFlag desc", connection2);
            SqlDataReader reader2 = command.ExecuteReader(CommandBehavior.CloseConnection);
            while (reader2.Read())
            {
                switch (reader2["StandFlag"].ToString())
                {
                    case "D":
                        str25 = reader2["MinValue"].ToString();
                        str26 = reader2["MaxValue"].ToString();
                        break;

                    case "C":
                        str23 = reader2["MinValue"].ToString();
                        str24 = reader2["MaxValue"].ToString();
                        break;

                    case "B":
                        str21 = reader2["MinValue"].ToString();
                        str22 = reader2["MaxValue"].ToString();
                        break;

                    case "A":
                        str19 = reader2["MinValue"].ToString();
                        str20 = reader2["MaxValue"].ToString();
                        break;
                }
            }
            reader2.Close();
            command.Dispose();
            connection2.Close();
            connection2.Dispose();
            SqlConnection connection = new SqlConnection(connectionString);
            connection.Open();
            SqlDataReader reader = new SqlCommand("select ID,DeptName from DeptInfo where UPID=" + string_4, connection).ExecuteReader(CommandBehavior.CloseConnection);
            while (reader.Read())
            {
                strArray[num, 0] = reader["ID"].ToString();
                strArray[num, 1] = reader["DeptName"].ToString();
                strArray[num, 2] = this.publicFun_0.GetValues(string.Concat(new object[] { "select Count(*) as UserCount from ExamUser a,UserInfo b where a.PaperID=", this.int_0, " and a.UserCode=b.UserCode and b.DeptID in( select b.ID from DeptInfo b where ", this.publicFun_0.GetManagDeptID(reader["ID"].ToString()), ")" }), "UserCount");
                strArray[num, 3] = this.publicFun_0.GetValues(string.Concat(new object[] { "select Count(*) as UserCount from ExamUser a,UserInfo b where a.PaperID=", this.int_0, " and a.UserCode=b.UserCode and a.Flag<>'A' and b.DeptID in( select b.ID from DeptInfo b where ", this.publicFun_0.GetManagDeptID(reader["ID"].ToString()), ")" }), "UserCount");
                if (!(strArray[num, 2].Trim() != "0"))
                {
                    strArray[num, 4] = "0";
                }
                else
                {
                    num3 = Convert.ToDouble(strArray[num, 3].Trim()) / Convert.ToDouble(strArray[num, 2].Trim());
                    num3 *= 100.0;
                    strArray[num, 4] = num3.ToString("0.00");
                }
                strArray[num, 5] = this.publicFun_0.GetValues(string.Concat(new object[] { "select Count(*) as UserCount from ExamUser a,UserInfo b where a.Flag<>'A' and  a.PaperID=", this.int_0, " and a.UserCode=b.UserCode and (a.GetCountFen>=", str25, " and a.GetCountFen<=", str26, ") and b.DeptID in( select b.ID from DeptInfo b where ", this.publicFun_0.GetManagDeptID(reader["ID"].ToString()), ")" }), "UserCount");
                if (strArray[num, 3].Trim() != "0")
                {
                    num3 = Convert.ToDouble(strArray[num, 5].Trim()) / Convert.ToDouble(strArray[num, 3].Trim());
                    num3 *= 100.0;
                    strArray[num, 6] = num3.ToString("0.00");
                }
                else
                {
                    strArray[num, 6] = "0";
                }
                strArray[num, 7] = this.publicFun_0.GetValues(string.Concat(new object[] { "select Count(*) as UserCount from ExamUser a,UserInfo b where a.Flag<>'A' and  a.PaperID=", this.int_0, " and a.UserCode=b.UserCode and (a.GetCountFen>=", str23, " and a.GetCountFen<=", str24, ") and b.DeptID in( select b.ID from DeptInfo b where ", this.publicFun_0.GetManagDeptID(reader["ID"].ToString()), ")" }), "UserCount");
                if (strArray[num, 3].Trim() != "0")
                {
                    num3 = Convert.ToDouble(strArray[num, 7].Trim()) / Convert.ToDouble(strArray[num, 3].Trim());
                    num3 *= 100.0;
                    strArray[num, 8] = num3.ToString("0.00");
                }
                else
                {
                    strArray[num, 8] = "0";
                }
                strArray[num, 9] = this.publicFun_0.GetValues(string.Concat(new object[] { "select Count(*) as UserCount from ExamUser a,UserInfo b where a.Flag<>'A' and  a.PaperID=", this.int_0, " and a.UserCode=b.UserCode and (a.GetCountFen>=", str21, " and a.GetCountFen<=", str22, ") and b.DeptID in( select b.ID from DeptInfo b where ", this.publicFun_0.GetManagDeptID(reader["ID"].ToString()), ")" }), "UserCount");
                if (!(strArray[num, 3].Trim() != "0"))
                {
                    strArray[num, 10] = "0";
                }
                else
                {
                    num3 = Convert.ToDouble(strArray[num, 9].Trim()) / Convert.ToDouble(strArray[num, 3].Trim());
                    num3 *= 100.0;
                    strArray[num, 10] = num3.ToString("0.00");
                }
                strArray[num, 11] = this.publicFun_0.GetValues(string.Concat(new object[] { "select Count(*) as UserCount from ExamUser a,UserInfo b where a.Flag<>'A' and a.PaperID=", this.int_0, " and  a.UserCode=b.UserCode and (a.GetCountFen>=", str19, " and a.GetCountFen<=", str20, ") and b.DeptID in( select b.ID from DeptInfo b where ", this.publicFun_0.GetManagDeptID(reader["ID"].ToString()), ")" }), "UserCount");
                if (!(strArray[num, 3].Trim() != "0"))
                {
                    strArray[num, 12] = "0";
                }
                else
                {
                    num3 = Convert.ToDouble(strArray[num, 11].Trim()) / Convert.ToDouble(strArray[num, 3].Trim());
                    num3 *= 100.0;
                    strArray[num, 12] = num3.ToString("0.00");
                }
                values = this.publicFun_0.GetValues(string.Concat(new object[] { "select ROUND(sum(GetCountFen),2) as GetCountFen  from ExamUser a,UserInfo b where a.Flag<>'A' and a.PaperID=", this.int_0, " and  a.UserCode=b.UserCode and b.DeptID in( select b.ID from DeptInfo b where ", this.publicFun_0.GetManagDeptID(reader["ID"].ToString()), ")" }), "GetCountFen");
                if (!(values.Trim() != ""))
                {
                    num2 = 0.0;
                }
                else
                {
                    num2 = Convert.ToDouble(values.Trim());
                }
                string str18 = this.publicFun_0.GetValues("select ParmValue from SysParmInfo where ParmMemo='GradeReport'", "ParmValue").Trim();
                if ((str18.Trim() == "") || (str18.Trim() == "Y"))
                {
                    if (!(strArray[num, 3].Trim() != "0"))
                    {
                        strArray[num, 14] = "0.00";
                    }
                    else
                    {
                        num3 = Convert.ToDouble(strArray[num, 2].Trim());
                        num3 = num2 / num3;
                        strArray[num, 14] = num3.ToString("0.00");
                    }
                }
                else if (!(strArray[num, 3].Trim() != "0"))
                {
                    strArray[num, 14] = "0.00";
                }
                else
                {
                    num3 = Convert.ToDouble(strArray[num, 3].Trim());
                    num3 = num2 / num3;
                    strArray[num, 14] = num3.ToString("0.00");
                }
                strArray[num, 15] = "0";
                num++;
            }
            reader.Close();
            connection.Close();
            connection.Dispose();
            string str16 = "合计";
            string str15 = "0";
            string str7 = "0";
            string str17 = "0";
            string str14 = "0";
            string str13 = "0";
            string str12 = "0";
            string str10 = "0";
            string str11 = "0";
            string str9 = "0";
            string str8 = "0";
            string str6 = "0";
            string str5 = "0";
            values = "";
            for (int i = 0; i < this.int_1; i++)
            {
                for (int k = 0; k < i; k++)
                {
                    if (Convert.ToDouble(strArray[i, 14]) >= Convert.ToDouble(strArray[k, 14]))
                    {
                        values = strArray[i, 0];
                        strArray[i, 0] = strArray[k, 0];
                        strArray[k, 0] = values;
                        values = strArray[i, 1];
                        strArray[i, 1] = strArray[k, 1];
                        strArray[k, 1] = values;
                        values = strArray[i, 2];
                        strArray[i, 2] = strArray[k, 2];
                        strArray[k, 2] = values;
                        values = strArray[i, 3];
                        strArray[i, 3] = strArray[k, 3];
                        strArray[k, 3] = values;
                        values = strArray[i, 4];
                        strArray[i, 4] = strArray[k, 4];
                        strArray[k, 4] = values;
                        values = strArray[i, 5];
                        strArray[i, 5] = strArray[k, 5];
                        strArray[k, 5] = values;
                        values = strArray[i, 6];
                        strArray[i, 6] = strArray[k, 6];
                        strArray[k, 6] = values;
                        values = strArray[i, 7];
                        strArray[i, 7] = strArray[k, 7];
                        strArray[k, 7] = values;
                        values = strArray[i, 8];
                        strArray[i, 8] = strArray[k, 8];
                        strArray[k, 8] = values;
                        values = strArray[i, 9];
                        strArray[i, 9] = strArray[k, 9];
                        strArray[k, 9] = values;
                        values = strArray[i, 10];
                        strArray[i, 10] = strArray[k, 10];
                        strArray[k, 10] = values;
                        values = strArray[i, 11];
                        strArray[i, 11] = strArray[k, 11];
                        strArray[k, 11] = values;
                        values = strArray[i, 12];
                        strArray[i, 12] = strArray[k, 12];
                        strArray[k, 12] = values;
                        values = strArray[i, 14];
                        strArray[i, 14] = strArray[k, 14];
                        strArray[k, 14] = values;
                    }
                }
            }
            values = "";
            int num7 = 0;
            double num6 = 0.0;
            double num5 = 0.0;
            for (int j = 0; j < this.int_1; j++)
            {
                num = 0;
                num = j + 1;
                values = values + "<tr height='30'>";
                values = ((((((((((((string.Concat(new object[] { values, "<td align='center'>", num, "</td>" }) + "<td align='center'>" + strArray[j, 1].Trim() + "</td>") + "<td align='center'>" + strArray[j, 2].Trim() + "</td>") + "<td align='center'>" + strArray[j, 3].Trim() + "</td>") + "<td align='center'>" + strArray[j, 4].Trim() + "</td>") + "<td align='center'>" + strArray[j, 5].Trim() + "</td>") + "<td align='center'>" + strArray[j, 6].Trim() + "</td>") + "<td align='center'>" + strArray[j, 7].Trim() + "</td>") + "<td align='center'>" + strArray[j, 8].Trim() + "</td>") + "<td align='center'>" + strArray[j, 9].Trim() + "</td>") + "<td align='center'>" + strArray[j, 10].Trim() + "</td>") + "<td align='center'>" + strArray[j, 11].Trim() + "</td>") + "<td align='center'>" + strArray[j, 12].Trim() + "</td>") + "<td align='center'>" + strArray[j, 14].Trim() + "</td>";
                num5 = Convert.ToDouble(strArray[j, 14].Trim());
                if (j == 0)
                {
                    values = values + "<td align='center'><B>1</B></td>";
                    num7 = 1;
                }
                else if (num5 == num6)
                {
                    values = string.Concat(new object[] { values, "<td align='center'><B>", num7, "</B></td>" });
                }
                else
                {
                    num7++;
                    values = string.Concat(new object[] { values, "<td align='center'><B>", num7, "</B></td>" });
                }
                num6 = num5;
                values = values + "</tr>";
                if (num != 1)
                {
                    str15 = Convert.ToString((double) (Convert.ToDouble(str15) + Convert.ToDouble(strArray[j, 2].Trim())));
                    str7 = Convert.ToString((double) (Convert.ToDouble(str7) + Convert.ToDouble(strArray[j, 3].Trim())));
                    str17 = Convert.ToString((double) (Convert.ToDouble(str17) + Convert.ToDouble(strArray[j, 4].Trim())));
                    str14 = Convert.ToString((double) (Convert.ToDouble(str14) + Convert.ToDouble(strArray[j, 5].Trim())));
                    str13 = Convert.ToString((double) (Convert.ToDouble(str13) + Convert.ToDouble(strArray[j, 6].Trim())));
                    str12 = Convert.ToString((double) (Convert.ToDouble(str12) + Convert.ToDouble(strArray[j, 7].Trim())));
                    str10 = Convert.ToString((double) (Convert.ToDouble(str10) + Convert.ToDouble(strArray[j, 8].Trim())));
                    str11 = Convert.ToString((double) (Convert.ToDouble(str11) + Convert.ToDouble(strArray[j, 9].Trim())));
                    str9 = Convert.ToString((double) (Convert.ToDouble(str9) + Convert.ToDouble(strArray[j, 10].Trim())));
                    str8 = Convert.ToString((double) (Convert.ToDouble(str8) + Convert.ToDouble(strArray[j, 11].Trim())));
                    str6 = Convert.ToString((double) (Convert.ToDouble(str6) + Convert.ToDouble(strArray[j, 12].Trim())));
                    str5 = Convert.ToString((double) (Convert.ToDouble(str5) + Convert.ToDouble(strArray[j, 14].Trim())));
                }
                else
                {
                    str15 = strArray[j, 2].Trim();
                    str7 = strArray[j, 3].Trim();
                    str17 = strArray[j, 4].Trim();
                    str14 = strArray[j, 5].Trim();
                    str13 = strArray[j, 6].Trim();
                    str12 = strArray[j, 7].Trim();
                    str10 = strArray[j, 8].Trim();
                    str11 = strArray[j, 9].Trim();
                    str9 = strArray[j, 10].Trim();
                    str8 = strArray[j, 11].Trim();
                    str6 = strArray[j, 12].Trim();
                    str5 = strArray[j, 14].Trim();
                }
                if (num == this.int_1)
                {
                    values = (((values + "<tr  height='30'>" + "<td align='center'>&nbsp;</td>") + "<td align='center'><B>" + str16 + "</B></td>") + "<td align='center'><B>" + str15 + "</B></td>") + "<td align='center'><B>" + str7 + "</B></td>";
                    if (!(str15.Trim() != "0"))
                    {
                        values = values + "<td align='center'><B>0</B></td>";
                    }
                    else
                    {
                        num3 = Convert.ToDouble(str7.Trim()) / Convert.ToDouble(str15.Trim());
                        num3 *= 100.0;
                        values = values + "<td align='center'><B>" + num3.ToString("0.00") + "</B></td>";
                    }
                    values = values + "<td align='center'><B>" + str14 + "</B></td>";
                    if (!(str7.Trim() != "0"))
                    {
                        str13 = "0";
                    }
                    else
                    {
                        num3 = Convert.ToDouble(str14.Trim()) / Convert.ToDouble(str7.Trim());
                        num3 *= 100.0;
                        str13 = num3.ToString("0.00");
                    }
                    values = (values + "<td align='center'><B>" + str13 + "</B></td>") + "<td align='center'><B>" + str12 + "</B></td>";
                    if (!(str7.Trim() != "0"))
                    {
                        str10 = "0";
                    }
                    else
                    {
                        num3 = Convert.ToDouble(str12.Trim()) / Convert.ToDouble(str7.Trim());
                        num3 *= 100.0;
                        str10 = num3.ToString("0.00");
                    }
                    values = (values + "<td align='center'><B>" + str10 + "</B></td>") + "<td align='center'><B>" + str11 + "</B></td>";
                    if (str7.Trim() != "0")
                    {
                        num3 = Convert.ToDouble(str11.Trim()) / Convert.ToDouble(str7.Trim());
                        num3 *= 100.0;
                        str9 = num3.ToString("0.00");
                    }
                    else
                    {
                        str9 = "0";
                    }
                    values = (values + "<td align='center'><B>" + str9 + "</B></td>") + "<td align='center'><B>" + str8 + "</B></td>";
                    if (str7.Trim() != "0")
                    {
                        num3 = Convert.ToDouble(str8.Trim()) / Convert.ToDouble(str7.Trim());
                        num3 *= 100.0;
                        str6 = num3.ToString("0.00");
                    }
                    else
                    {
                        str6 = "0";
                    }
                    values = values + "<td align='center'><B>" + str6 + "</B></td>";
                    if (str7.Trim() != "0")
                    {
                        str5 = (Convert.ToDouble(str5.Trim()) / Convert.ToDouble(this.int_1)).ToString("0.00");
                    }
                    else
                    {
                        str5 = "0";
                    }
                    values = (values + "<td align='center'><B>" + str5 + "</B></td>") + "<td align='center'>&nbsp;</td>" + "</tr>";
                }
            }
            return values;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.string_1 = Convert.ToInt32(base.Request["DeptID"]).ToString();
            this.string_2 = base.Server.UrlDecode(base.Request["DeptName"].ToString());
            this.string_3 = base.Request["Level"].ToString();
            this.int_0 = Convert.ToInt32(base.Request["PaperID"].ToString());
            base.Response.Cache.SetCacheability(HttpCacheability.NoCache);
            base.Response.Cache.SetNoStore();
            this.Page.Title = ConfigurationManager.ConnectionStrings["ProTitle"].ConnectionString + "---考试成绩报表分析";
            if (!base.IsPostBack)
            {
                if (this.publicFun_0.ReturnPaperData() != "Yes")
                {
                    ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BCheck", "alert('此版本暂未授权,请拔打(0)13870606104手机号进行授权！')", true);
                }
                else
                {
                    string connectionString = "";
                    string str2 = "0";
                    connectionString = ConfigurationManager.ConnectionStrings["Conn"].ConnectionString;
                    SqlConnection connection2 = new SqlConnection(connectionString);
                    connection2.Open();
                    SqlDataReader reader2 = new SqlCommand("select ExamName,PaperStartTime,PaperEndTime from PaperInfo where ID=" + this.int_0, connection2).ExecuteReader(CommandBehavior.CloseConnection);
                    if (reader2.Read())
                    {
                        this.labTitle.Text = "【" + reader2["ExamName"].ToString() + "】考试成绩综合统计分析表";
                        this.string_0 = reader2["PaperStartTime"].ToString() + "--" + reader2["PaperEndTime"].ToString();
                    }
                    reader2.Close();
                    connection2.Close();
                    connection2.Dispose();
                    if (!(this.string_3 == "C"))
                    {
                        this.method_0(this.string_1, this.string_2, this.string_1);
                        str2 = this.string_1;
                    }
                    else
                    {
                        this.method_0("0", "单位总表", "0");
                        str2 = "0";
                    }
                    SqlConnection connection = new SqlConnection(connectionString);
                    connection.Open();
                    SqlDataReader reader = new SqlCommand("select ID,DeptName from DeptInfo where UPID=" + str2 + " order by SortInfo", connection).ExecuteReader(CommandBehavior.CloseConnection);
                    while (reader.Read())
                    {
                        this.method_0(reader["ID"].ToString(), reader["DeptName"].ToString(), "1");
                    }
                    reader.Close();
                    connection.Close();
                    connection.Dispose();
                }
            }
        }
    }
}

